package com.yyjj.my.activity;

import android.graphics.Color;
import android.os.Bundle;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.aries.ui.view.title.TitleBarView;
import com.avos.avoscloud.AVException;
import com.avos.avoscloud.AVObject;
import com.avos.avoscloud.AVQuery;
import com.avos.avoscloud.FindCallback;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.vise.xsnow.http.ViseHttp;
import com.vise.xsnow.http.callback.ACallback;
import com.yyjj.my.R;
import com.yyjj.my.adapter.MessageAdapter;
import com.yyjj.my.api.ApiConstant;
import com.yyjj.my.entity.CircleList;

import java.util.List;

import tech.com.commoncore.app.FastManager;
import tech.com.commoncore.base.BaseRefreshLoadActivity;
import tech.com.commoncore.entity.BaseTResp;

@Route(path = "/my/msg")
public class MsgActivity extends BaseRefreshLoadActivity<AVObject> {


    @Override
    public void setTitleBar(TitleBarView titleBar) {
        titleBar.setTitleMainText(getResources().getString(R.string.my_msg)).setTextColor(Color.WHITE);
    }

    @Override
    public int getContentLayout() {
        return R.layout.my_activity_msg;
    }

    @Override
    public void initView(Bundle savedInstanceState) {
    }


    @Override
    public BaseQuickAdapter<AVObject, BaseViewHolder> getAdapter() {
        return new MessageAdapter();
    }

    @Override
    public void loadData(int page) {
        ViseHttp.GET(ApiConstant.CIRCLE_LIST)
                .baseUrl(ApiConstant.C_URL)
                .addParam("page", page + 1 + "")
                .addParam("num", mDefaultPageSize + "")
                .addParam("category", "179")
                .request(new ACallback<BaseTResp<CircleList>>() {

                    @Override
                    public void onSuccess(BaseTResp<CircleList> data) {
                        if ((1 == data.code) && (data.data != null)) {
                            FastManager.getInstance().getHttpRequestControl().httpRequestSuccess(getIHttpRequestControl(), data.data.data, null);
                        } else {
                            FastManager.getInstance().getHttpRequestControl().httpRequestSuccess(getIHttpRequestControl(), null, null);
                        }
                    }

                    @Override
                    public void onFail(int errCode, String errMsg) {
                        FastManager.getInstance().getHttpRequestControl().httpRequestError(getIHttpRequestControl(), errCode + "", errMsg);
                    }
                });



//        AVQuery<AVObject> query = new AVQuery<>("Message");
//        query.setLimit(10);
//        query.setSkip(page * 10);
//        query.orderByDescending("createdAt");
//        query.findInBackground(new FindCallback<AVObject>() {
//            @Override
//            public void done(List<AVObject> list, AVException e) {
//                // list 是一个 AVObject 的 List
//                // list 指的就是所有包含当前 tag 的 TodoFolder
//                if (e == null) {
//                    FastManager.getInstance().getHttpRequestControl().httpRequestSuccess(getIHttpRequestControl(), list, null);
//                } else {
//                    FastManager.getInstance().getHttpRequestControl().httpRequestError(getIHttpRequestControl(), e.getCode() + "", e.getMessage());
//                }
//
//            }
//        });
    }
}
